<?php
namespace Home\Controller;
use Home\Event\UserEvent;
use Think\Controller;
use Think\Model;
use Think\Upload;
use Think\Verify;

class UserController extends Controller{
    public function index(){
        $this->assign('user', '蜡笔小新ss');
        L('name', 'Evan');
        echo L('_CONTROLLER_NOT_EXIST_');
        $this->display();
        
//         $data = new \stdClass();
//         $data->name = 'wanwencheng';
        
        //过滤内容
//         $content = $this->fetch();
//         $this->show($content);
    }

    public function lang(){
        setcookie('think_language','en-us');
    }

    public function upload(){
        $upload = new Upload();
        $upload->maxSize = 3145728;
        $upload->exts = array('jpg','jpeg','gif','png');
        $upload->savePath ='./';
        //$upload->autoSub = false;   //设置子目录
        $upload->subName = array('date', 'Ymd');
        //$upload->subName = 'get_user_id';
        $info = $upload->upload();
        if(!$info)
        {
            $this->error($upload->getError());
        } else{
            $this->success("上传成功");
            foreach($info as $file){
                echo $file['savepath'].$file['filename'].'<br/>';
            }

        }


    }

    public function test(){
        $userEvent = new UserEvent();
        $userEvent->test();
        echo 'test';
    }

    public function go(){
        $config = array(
            'fontSize'=> 50,
            'length'=>4,
            'userNoise'=>false,
        );
        $verfiy = new Verify($config);
        $verfiy->fontttf = '5.ttf';
        $verfiy->useImgBg = true;
        $verfiy->useCurve = false;
        $verfiy->codeSet = '0123456789';
        $verfiy->entry();
    }

    public function _before_test(){
        echo '在之前执行';
    }
    public function _after_test(){
        echo '在之前执行';
    }
    
    public function select(){
        $user = 'evan';
        $this->assign('user', $user);
        $this->display();
    }
    
    public function add(){
        $user = D('User');
        $data['user'] = '蜡笔小新';
        if($user->create($data)){
            $user->add();
        }
    }
    
    public function model(){
        //创建Model基类 传递User类  think_user;
//         $user = new Model('User','think_');
//         var_dump($user->select());

        $user = M('User');
        var_dump($user->where('id IN (1,2,3,4)')->find());
    }
    
    public function create(){
        $user=M('User');
        var_dump($user->create());
    }
}